package edu.asu.cse360.dto;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.Serializable;

import javax.imageio.ImageIO;

public class ImageDto implements Serializable{

    private static final long serialVersionUID = -1558817710841652444L;
    private String absolutePath;
    private BufferedImage image;

    public ImageDto(String absolutePath, BufferedImage image){
        this.absolutePath = absolutePath;
        this.image = image;
    }

    private void writeObject(java.io.ObjectOutputStream out)throws IOException{
        out.writeObject(absolutePath);
        ImageIO.write(image,"jpeg",ImageIO.createImageOutputStream(out));
    }

    private void readObject(java.io.ObjectInputStream in)throws IOException, ClassNotFoundException{
        absolutePath = in.readObject().toString();
        image = ImageIO.read(ImageIO.createImageInputStream(in));
    }

    public BufferedImage getImage(){
        return image;
    }


    public String getAbsolutePath(){
        return absolutePath;
    }

    public int getHeight(){
        return image.getHeight();
    }

    public int getWidth(){
        return image.getWidth();
    }

}
